<?php
namespace Tbf\Component\Io\Buffer;
use Tbf\Component\Arrays\ArrayReaderInterface;
use Tbf\Component\Arrays\ArrayWriterInterface;
class ArrayBuffer implements ArrayReaderInterface,ArrayWriterInterface
{
    protected $buffer = array();
    public function __construct($data = array())
    {
        foreach ($data as $row) {
            $this->writeRow($row);
        }
    }
    public function readRow()
    {
        if ($this->buffer===array() ) {
            return null;
        }

        return array_shift($this->buffer);
    }
    public function writeRow(array $array)
    {
        $this->buffer[] = $array;
    }
}
